package com.maybach.workflow.core.config.parser;

import com.maybach.util.AssertUtil;
import com.maybach.workflow.common.api.enums.ActorTypeEnum;
import com.maybach.workflow.common.api.node.TaskActor;
import org.apache.commons.lang.StringUtils;
import org.w3c.dom.Element;

/**
 * Created by houenxun on 16/1/21.
 */
public class TaskActorParser extends AbstractParser<TaskActor> {
    public TaskActorParser() {
        super(NodeParser.NODE_NAME_ACTOR);
    }

    @Override
    public TaskActor createNode() {
        return new TaskActor();
    }

    @Override
    public void parseSpecial(Element element, TaskActor taskActor) {
        taskActor.setExpression(element.getAttribute(NodeParser.ATTR_EXPRESSION));
        taskActor.setValue(element.getAttribute(NodeParser.ATTR_ACTOR_VALUE));
        taskActor.setActorType(ActorTypeEnum.valueOf(element.getAttribute(NodeParser.ATTR_ACTOR_TYPE)));
    }

    @Override
    public void check(TaskActor taskActor) {
        AssertUtil.isTrue(StringUtils.isNotBlank(taskActor.getExpression()) || StringUtils.isNotBlank(taskActor.getValue()), "value=" + taskActor.getValue() + ", expression=" + taskActor.getExpression());
    }
}
